<?php 	

	/**
	 * 短信类服务
	 */
	class SdkSmsService extends Service {
		private $url = '';
		private $channelid = 10000;

		/**
		 * [send 发送短信]
		 * @param  [type] $phone [description]
		 * @param  [type] $optype  [description]
		 * @return [type]        [description]
		 */
		public function send($phone, $optype) {
			if (!Validator::checkPhone($phone)) {
				$this->error = '请输入正确的手机号码';
				return false;
			}

			$jsonparams[0]['cmd'] = 401;
			$jsonparams[0]['phone'] = $phone;
			$jsonparams[0]['optype'] = $optype;

			$res = $this->request($jsonparams);
			return $res!==false;
		}

		/**
		 * [check 验证短信]
		 * @param  [type] $phone     [description]
		 * @param  [type] $smscode    [description]
		 * @return [type]            [description]
		 */
		public function check($phone, $smscode) {
			if (!Validator::checkPhone($phone)) {
				$this->error = '请输入正确的手机号码';
				return false;
			}

			$jsonparams[0]['cmd'] = 402;
			$jsonparams[0]['phone'] = $phone;
			$rsa = new Rsa();
            $smscode = $rsa->noPaddingStr($smscode);
			$jsonparams[0]['smscode'] = $rsa->sdk_encrypt($smscode);

			$res = $this->request($jsonparams);
			return $res!==false;
		}

		/**
		 * [request 发送请求]
		 * @param  Array  $jsonparams [description]
		 * @return [type]             [description]
		 */
		private function request(Array $jsonparams) {
			$params['params'] = json_encode($jsonparams);
			$params['r'] = 'api/index';
			$params['channelid'] = intval($this->channelid);
			$params['appid'] = 10;
			$params['sign'] = md5(CommonUtil::encodePassword('473122a9fcfe46ca26915af8a9d0696d').$params['appid'].$params['channelid'].$params['params']);

			$this->url = SDK_API_HOST . "/index.php";

			return $this->httpGet($params, $this->url);
		}
	}